<template>
  <el-form ref="form" label-width="120px" style="margin:20px;width:90%;">
    <div style="width:100%; float:left">
      <el-form-item
        label="0.5kg内(普通)"
        style="margin:10px; width:30%; float:left;white-space:nowrap;"
      >
        <el-input v-model="nearPrice1" type="number" placeholder="单位：元"></el-input>
      </el-form-item>
      <el-form-item
        label="0.5-1kg内(普通)"
        style="margin:10px; width:30%; float:left;white-space:nowrap;"
      >
        <el-input v-model="nearPrice2" type="number" placeholder="单位：元"></el-input>
      </el-form-item>
      <el-form-item label="续重(普通)" style="margin:10px; width:30%; float:left;white-space:nowrap;">
        <el-input v-model="nearPrice3" type="number" placeholder="单位：元"></el-input>
      </el-form-item>

      <el-form-item
        label="0.5kg内(偏远)"
        style="margin:10px; width:30%; float:left;white-space:nowrap;"
      >
        <el-input v-model="farPrice1" type="number" placeholder="单位：元"></el-input>
      </el-form-item>
      <el-form-item
        label="0.5-1kg内(偏远)"
        style="margin:10px; width:30%; float:left;white-space:nowrap;"
      >
        <el-input v-model="farPrice2" type="number" placeholder="单位：元"></el-input>
      </el-form-item>
      <el-form-item label="续重(偏远)" style="margin:10px; width:30%; float:left;white-space:nowrap;">
        <el-input v-model="farPrice3" type="number" placeholder="单位：元"></el-input>
      </el-form-item>
    </div>
    <div style="width:100%; float:left">
      <el-form-item style="margin:10px;">
        <el-button type="primary" @click="register">立即提交</el-button>
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      id: "",
      nearPrice1: "",
      nearPrice2: "",
      nearPrice3: "",
      farPrice1: "",
      farPrice2: "",
      farPrice3: ""
    };
  },
  methods: {
    getData() {
      let that = this;
      this.axios
        .get("/expressPrice", {
          headers: {
            Authorization: sessionStorage.getItem("token"),
            "Content-Type": "application/x-www-form-urlencoded",
            domain: "taobao.tianyalei.com"
          }
        })
        .then(res => {
					var arry=res.data.data;
					for(var i=0;i<arry.length;i++){
							if(arry[i].vip==-1){
									that.id=arry[i].id;
									that.nearPrice1=arry[i].nearPrice1/100;
									that.nearPrice2=arry[i].nearPrice2/100;
									that.nearPrice3=arry[i].nearPrice3/100;
									that.farPrice1=arry[i].farPrice1/100;
									that.farPrice2=arry[i].farPrice2/100;
									that.farPrice3=arry[i].farPrice3/100;
							}
					}
        });
    },
    register() {
      let that = this;
      if(that.id){
				this.axios
        .put(
          "/expressPrice",
          this.qs.stringify({
						id:that.id,
            nearPrice1: this.nearPrice1*100,
            nearPrice2: this.nearPrice2*100,
            nearPrice3: this.nearPrice3*100,
            farPrice1: this.farPrice1*100,
            farPrice2: this.farPrice2*100,
            farPrice3: this.farPrice3*100,
            vip: -1,
            forUser: false
          }),
          {
            headers: {
              Authorization: sessionStorage.getItem("token"),
              "Content-Type": "application/x-www-form-urlencoded",
              domain: "taobao.tianyalei.com"
            }
          }
        )
        .then(function(response) {
          if (response.data.code == 200) {
            that.$message({
              message: "提交成功",
              type: "success"
            });
          }
        });	
			}else{
				this.axios
        .post(
          "/expressPrice",
          this.qs.stringify({
            nearPrice1: this.nearPrice1*100,
            nearPrice2: this.nearPrice2*100,
            nearPrice3: this.nearPrice3*100,
            farPrice1: this.farPrice1*100,
            farPrice2: this.farPrice2*100,
            farPrice3: this.farPrice3*100,
            vip: -1,
            forUser: false
          }),
          {
            headers: {
              Authorization: sessionStorage.getItem("token"),
              "Content-Type": "application/x-www-form-urlencoded",
              domain: "taobao.tianyalei.com"
            }
          }
        )
        .then(function(response) {
          if (response.data.code == 200) {
            that.$message({
              message: "提交成功",
              type: "success"
            });
          }
        });
			}
    }
  },
  created() {
    this.getData();
  }
};
</script>
<style>
</style>
